{% extends './layout.html' %} {% block title %} {{ title }} {% endblock %}{% block crumbs %}
<a href="/">首页</a>
<a><cite>采集网站管理</cite></a>
{% endblock %} {% block body %}
<div class="layout_head">
	<button type="button" class="layui-btn layui-btn-sm" id="addCaptureSite"><i class="layui-icon">&#xe608;</i> 新增采集网站</button>
</div>
<div class="layout_cont">
	<table class="layui-table">
		<colgroup>
			<col width="120">
			<col width="25%">
			<col>
			<col width="100">
		</colgroup>
		<thead>
			<tr>
				<th>网站编号</th>
				<th>网站名称</th>
				<th>网站域名</th>
				<th>操作</th>
			</tr>
		</thead>
		<tbody id="captureList">
			{% for index,item in list %}
			<tr>
				<td>{{ index+1 }}</td>
				<td>{{ item.sitename }}</td>
				<td>{{ item.sitehref }}</td>
				<td>
					<div class="layui-btn-group">
						<button type="button" class="layui-btn layui-btn-xs layui-btn-warm" data-type="edit" data-datas='{{item | jsonformat}}'>编辑</button>
						<button type="button" class="layui-btn layui-btn-xs layui-btn-danger" data-type="del" data-id="{{item.id}}">删除</button>
					</div>
				</td>
			</tr>
			{% endfor %}
		</tbody>
	</table>
</div>
{% endblock %} {% block template %}
<form class="layui-form" id="captureForm" lay-filter="captureForm" style="display:none; padding: 20px 20px 0 0;">
	<div class="layui-form-item">
		<label class="layui-form-label">网站名称</label>
		<div class="layui-input-block" style="width: 50%;">
			<input type="text" name="sitename" lay-verify="required" autocomplete="off" placeholder="请输入小说名称" class="layui-input">
		</div>
	</div>
	<div class="layui-form-item">
		<label class="layui-form-label">网站域名</label>
		<div class="layui-input-block">
			<input type="text" name="sitehref" placeholder="请输入小说作者" autocomplete="off" class="layui-input">
		</div>
	</div>
</form>
{% endblock %} {% block scripts %}
<script type="text/javascript">
	layui.use(['layer', 'form'], function() {
		var $ = layui.jquery;
		var form = layui.form;
		var layer = layui.layer;
		$('#addCaptureSite').on('click', function() {
			layer.open({
				type: 1,
				title: '添加采集站点',
				content: $("#captureForm"),
				area: ['560px', 'auto'],
				btn: ['提交', '重置'],
				btnAlign: 'c',
				yes: function(index, layero) {
					var params = form.val('captureForm');
					$.post('/capture/create', params, function(data) {
						if (data.code == 200 && data.success) {
							layer.close(index);
							window.location.reload();
						}
					});
				}
			});
		});
		$('#captureList').on('click', 'button.layui-btn', function() {
			var type = $(this).data('type');
			switch (type) {
				case 'edit':
					var datas = $(this).data('datas');
					layer.open({
						type: 1,
						title: '添加采集站点',
						content: $("#captureForm"),
						area: ['560px', 'auto'],
						btn: ['提交', '取消'],
						btnAlign: 'c',
						success: function() {
							form.val('captureForm', {
								sitename: datas.sitename,
								sitehref: datas.sitehref
							})
						},
						yes: function(index, layero) {
							var params = form.val('captureForm');
							params.id = datas.id;
							$.post('/capture/update', params, function(data) {
								if (data.code == 200 && data.success) {
									layer.close(index);
									window.location.reload();
								}
							})
						}
					});
					break;
				case 'del':
					var id = $(this).data('id');
					layer.confirm('是否删除当前采集网站？', {
						btnAlign: 'c',
						title: '删除确认'
					}, function(index) {
						$.post('/capture/delete', {
							id: id
						}, function(data) {
							layer.close(index);
							window.location.reload();
						});
					});
					break;
			}
		})
	});
</script>
{% endblock %}
